<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>个人中心</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/templatemo-style.css">
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
<script type="text/javascript">

		function editPerAjax(){
			var username=document.getElementById("na").value;
			var sex=document.getElementById("se").value;
			var age=document.getElementById("ag").value;
			var telephone=document.getElementById("te").value;
            var username_md5 = md5(username);
            var arry2;
            var user_id;
            
    		let re = new RegExp("\s?" + "username" + "=([^;]+)(;|$)")
    		var username1=document.cookie.match(re)[1];
    		
            $.ajax({
	            url: "http://localhost:8080/voting-system/getUserId",
	            type: "post",
	            success:function (data) {
	            	arry2=data;
	            	user_id=arry2["UserId"];
	            	 $.ajax({
	                        url: "http://localhost:8080/voting-system/updateUser",
	                        type: "post",
	                        success:function (data) {
	                        	if(data.updateUser==false){
	                        		alert("修改失败！")
	                        	}else{
	                        		alert("修改成功！")
	                        	}
	                        },
	                        dataType: "json",
	                        data:{user_id:user_id, username:username, sex:sex, age:age, telephone:telephone, username_md5:username_md5}
	                  });
	            },
	            dataType: "json",
	            data:{username:username1}
	        });
               
		}
</script>
<body id="reportsPage">
	<div class="" id="home">
		<nav class="navbar navbar-expand-xl">
			<div class="container h-100">
				<h1 class="tm-site-title mb-0">个人中心</h1>

				<button class="navbar-toggler ml-auto mr-0" type="button"
					data-toggle="collapse" data-target="#navbarSupportedContent"
					aria-controls="navbarSupportedContent" aria-expanded="false"
					aria-label="Toggle navigation">
					<i class="fas fa-bars tm-nav-icon"></i>
				</button>

				<div class="collapse navbar-collapse" id="navbarSupportedContent">
					<ul class="navbar-nav mx-auto h-100">
						<li class="nav-item"><a class="nav-link" href="result.jsp">
								<i class="fas fa-tachometer-alt"></i> 投票结果 <span class="sr-only">(current)</span>
						</a></li>

						<li class="nav-item"><a class="nav-link" href="vote.html">
								<i class="fas fa-shopping-cart"></i> 学生投票
						</a></li>

						<li class="nav-item"><a class="nav-link active"
							href="personal.html"> <i class="far fa-user"></i> 个人中心
						</a></li>

					</ul>
					<ul class="navbar-nav">
						<li class="nav-item"><a class="nav-link d-block"
							href="../login.html"> <b>退出登录</b>
						</a></li>
					</ul>
				</div>
			</div>
		</nav>
		<div class="container mt-5" style="position: relative; left: 170px;">

			<div class="tm-block-col tm-col-account-settings">
				<div class="tm-bg-primary-dark tm-block tm-block-settings">
					<h2 class="tm-block-title">账号设置</h2>
					<form class="tm-signup-form row">
						<div class="form-group col-lg-6">
							<label for="name">用户名</label> <input name="na" type="text" id="na"
								class="form-control validate">
						</div>

						<div class="form-group col-lg-6">
							<label for="password">性别</label> <input name="se" type="text" id="se"
								class="form-control validate">
						</div>
						<div class="form-group col-lg-6">
							<label for="password2">年龄</label> <input name="ag" type="text" id="ag"
								class="form-control validate">
						</div>
						<div class="form-group col-lg-6">
							<label for="phone">电话</label> <input name="te" type="text" id="te"
								class="form-control validate">
						</div>

						<div class="col-12">
							<button type="button"
								class="btn btn-primary btn-block text-uppercase mb-3" onclick="editPerAjax()">
								确认更新</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	</div>


</body>
</html>
